from git import Repo
import time
import _thread


repo = Repo(".")
index = repo.index
# 获取默认版本库 origin
remote = repo.remote()

def pullData():
    remote.pull()

# 提交数据
def pushData():
    index.add(['data/data.json'])
    # index.remove(['old.txt'])
    index.commit('this is a auto commit')
    remote.push()

# 定期拉取数据
def regularPull(threadName, delay):
    while True:
        pullData()
        time.sleep(delay) #休眠秒数
        print ("%s: %s" % (threadName + " pull data ", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) ))
        
def startThreadChild():
    try:
        _thread.start_new_thread(regularPull, ("Thread-Child", 30))
    except:
        print ("Error: can't start _thread.")

startThreadChild()
